﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PSDManager.SystemSettings
{
    public partial class NetworkSettingPanel : UserControl, ISettingPanel
    {
        public ManagerHelper ManagerHelper { get; set; }
        public NetworkSettingPanel()
        {
            InitializeComponent();
        }

        public void ApplySettings()
        {
            SaveSettings();

            foreach (var p in AppSettings.Setting.API.GetType().GetProperties())
            {
                p.SetValue(AppSettings.Setting.API, AppSettings.Setting.ApiServerAddress + "api/VideoDownload/" + p.Name);
            }

            //ManagerHelper.UpdatePSDServerSetting(
            //    AppSettings.Setting.ApiServerAddress,
            //    AppSettings.Setting.TcpServerAddress,
            //    AppSettings.Setting.TcpServerPort);
        }

        public void LoadSettings()
        {
            this.txtApiServerAddress.Text = AppSettings.Setting.ApiServerAddress;
            this.txtTcpServerAddress.Text = AppSettings.Setting.TcpServerAddress;
            this.txtTcpServerPort.Text = AppSettings.Setting.TcpServerPort.ToString();
            this.txtPDMPort.Text = AppSettings.Setting.PDMListenPort.ToString();
        }

        public void SaveSettings()
        {
            AppSettings.Setting.ApiServerAddress = this.txtApiServerAddress.Text.Trim();
            AppSettings.Setting.TcpServerAddress = this.txtTcpServerAddress.Text.Trim();
            AppSettings.Setting.TcpServerPort = Convert.ToInt32(this.txtTcpServerPort.Text.Trim());
            AppSettings.Setting.PDMListenPort = Convert.ToInt32(this.txtPDMPort.Text.Trim());
        }
    }
}
